/**
 * @param {Egg.Application} app - egg application
 */
 const  validateParams  = require('./middlewares/validateParams')
 const  jwtMidd  = require('./middlewares/jwt')
 const  { loginSchema,signSchema } = require('./validator/user')
 const  { addPokeSchema,deletePokeSchema } = require('./validator/pokemon')
 const  { addInvatation } = require('./validator/invatation')
 const  { addComment } = require('./validator/comment')
 const  { addArticle } = require('./validator/article')


module.exports = app => {
  const { router, controller } = app;
  const jwt = jwtMidd(app.config.jwt);

  // 用户相关
  router.get('/', controller.home.index);
  router.get('/check',jwt, controller.home.check);
  router.post('/login', validateParams('post', loginSchema),controller.home.login);
  router.post('/sign',  validateParams('post', signSchema), controller.home.sign);
  router.get('/user/page',jwt, controller.home.page);
  router.post('/user/add',jwt, controller.home.addUser);
  router.post('/user/update',jwt, controller.home.updateUser);
  router.post('/user/delete',jwt, controller.home.deleteUser);
  router.post('/user/updateSelf',jwt, controller.home.updateSelf);
  
  // 宝可梦图鉴相关
  router.get('/getPokemonPage',controller.pokemon.getPokemonPage);
  router.get('/getPokemon',controller.pokemon.getPokemon);
  router.post('/addPokemon',jwt, validateParams('post', addPokeSchema),controller.pokemon.addPokemon);
  router.post('/updatePokemon',jwt, validateParams('post', addPokeSchema),controller.pokemon.updatePokemon);
  router.post('/deletePokemon',jwt, validateParams('post', deletePokeSchema),controller.pokemon.deletePokemon);

  // 论坛相关
  router.get('/invatation/page',controller.invatation.getInvatationPage);
  router.post('/invatation/add', jwt,validateParams('post', addInvatation),controller.invatation.addInvatation);
  router.post('/invatation/delete', jwt,controller.invatation.delete);
  router.get('/comment/page',controller.comment.getCommentPage);
  router.post('/comment/add', jwt,validateParams('post', addComment),controller.comment.addComment);
  router.post('/comment/delete', jwt,controller.comment.delete);

  // 文章相关
  router.get('/article/page',controller.article.page);
  router.post('/article/add', jwt,validateParams('post', addArticle),controller.article.add);
  router.post('/article/delete', jwt,controller.article.delete);
  router.get('/article/comPage',controller.article.comPage);
  router.post('/article/addCom',jwt,controller.article.addCom);
  router.post('/article/deleteCom', jwt,controller.article.deleteCom);

  // 点赞相关
  router.post('/like', jwt,controller.like.addLike);
  router.post('/removelike', jwt,controller.like.removelike);
  router.get('/userlike', jwt,controller.like.userlike);
};
